package cn.geodata.dataview.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;

import cn.geodata.database.DataObject;
import cn.geodata.dataview.Fire;
import cn.geodata.dataview.FireFactory;

public class ImageInfo {
	private int path;
	private int row;
	
	private String result;
	
	public int getPath() {
		return path;
	}

	public void setPath(int path) {
		this.path = path;
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}
	
	public InputStream getResult() {
		return new ByteArrayInputStream(this.result.getBytes());
	}

	public String execute() throws Exception {
		StringBuilder _txt = new StringBuilder("{'result':[");
		
		boolean _isFirst = true;
		ArrayList<DataObject> _list = (new FireFactory()).list("path=" + this.path + " and row=" + this.row + " ORDER BY date DESC");
		for(DataObject _o : _list){
			Fire _fire = (Fire) _o;
			if(_isFirst){
				_isFirst = false;
			}
			else{
				_txt.append(",");
			}
			_txt.append(String.format("{'date':'%1$td/%1$tm/%1$ty','sensor':'%2$s','source':'%3$s','id':'%4$s','cloud':'%5$.1f'}", _fire.getDate(), _fire.getSensor(), _fire.getSource(), _fire.getId(), _fire.getCloud()));
		}
		
		_txt.append("]}");
		this.result = _txt.toString();
		
		return "success";
	}
}
